package cn.dong.cms.controller.admin;


import cn.dong.cms.domain.AdType;
import cn.dong.cms.service.AdTypeService;
import cn.dong.api.domain.CommonResult;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 推荐位 前端控制器
 * </p>
 *
 * @author You-Dong
 * @since 2021-02-17
 */
@RestController
@RequestMapping("/cms/ad-type")
public class AdTypeController {


    @Autowired
    private AdTypeService adTypeService;


    /**
     * 回显
     *
     * @param id
     * @return
     */
    @GetMapping("/findById/{id}")
    public CommonResult findById(@PathVariable String id) {
        AdType ad = adTypeService.getById(id);
        return CommonResult.ok().data(ad);
    }


    /**
     * 创建
     *
     * @param ad
     * @return
     */
    @PostMapping("/create")
    public CommonResult create(@RequestBody AdType ad) {
        return CommonResult.whether(adTypeService.save(ad));
    }


    /**
     * 修改
     *
     * @param ad
     * @return
     */
    @PutMapping("/update")
    public CommonResult update(@RequestBody AdType ad) {
        return CommonResult.whether(adTypeService.updateById(ad));
    }


    /**
     * 根据id删除
     *
     * @param id
     * @return
     */
    @DeleteMapping("/delete/{id}")
    public CommonResult delete(@PathVariable String id) {

        return CommonResult.whether(adTypeService.removeById(id));
    }


    /**
     * 根据条件查询全部
     *
     * @param current
     * @param size
     * @return
     */
    @GetMapping("/findByCondition/{current}/{size}")
    public CommonResult findByCondition(
            @PathVariable Integer current,
            @PathVariable Integer size) {
        IPage<AdType> adIPage = new Page<AdType>(current, size);
        IPage<AdType> page = adTypeService.page(adIPage);
        return CommonResult.ok().data(page);
    }


    /**
     * 查询全部
     *
     * @return
     */
    @GetMapping("/findAll")
    public CommonResult findALl() {
        return CommonResult.ok().data(adTypeService.list());
    }

}

